
package study.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.appengine.repackaged.com.google.common.collect.Maps;

/**
 * 홈 컨트롤러
 *
 * @author Barney Kim
 */
@Controller
public class HomeController {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@ModelAttribute("baseModels")
	public Map<String, Object> characterHomeModels(HttpServletRequest request) {
		Map<String, Object> models = Maps.newHashMap();
		String ctxRoot = request.getContextPath();
		String uri = request.getRequestURI();
		int len = 0;
		if(ctxRoot != null && ctxRoot.length() > 0) {
			len = uri.indexOf(ctxRoot) + ctxRoot.length();
		}
		uri = uri.substring(len);
		len = uri.split("/").length;
		if(len == 0) {
			models.put("menu", "/");
		} else
		if(len == 2) {
			models.put("menu", uri.split("/")[1]);
		}
		logger.debug("models={},uri={},len={}", new Object[] { models, uri, uri.split("/").length });
		return models;
	}

	/**
	 * 홈
	 */
	@RequestMapping(value={"/"}, method=RequestMethod.GET)
	public String home() {
		return "index";
	}

	/**
	 * 소개
	 */
	@RequestMapping(value={"/about"}, method=RequestMethod.GET)
	public String about() {
		return "about/about";
	}
}
// EOF